package com.mz.ieann.aide.pager.model

import androidx.lifecycle.MutableLiveData
import androidx.lifecycle.viewModelScope
import com.mz.ieann.aide.R
import com.mz.ieann.aide.base.vm.BaseViewModel
import com.mz.ieann.aide.pager.bean.WelComeContent
import com.mz.ieann.dokit.utils.LogUtils
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.launch
import kotlinx.coroutines.withContext

/**
 * <p>------------------------------------------------------
 * <p>Copyright (C) 2021 zhangmz, All rights reserved.
 * <p>------------------------------------------------------
 * <p> des
 * <p> https://ss0.baidu.com/94o3dSag_xI4khGko9WTAnF6hhy/baike/pic/item/a044ad345982b2b74099da9938adcbef76099b6d.jpg
 *
 * @author Created by Administrator
 * @date on 2021 2021/9/11 10:43
 */
class WelComeViewModel : BaseViewModel() {

    val imgList = MutableLiveData<ArrayList<WelComeContent>>()

    fun queryWelcomeImg(){
        viewModelScope.launch {
            withContext(Dispatchers.IO){
                val result = ArrayList<WelComeContent>(3)
                for (i in 0..2){
                    val bean = WelComeContent()
                    bean.index = i
                    bean.imgId = when(i){
                        0 -> R.mipmap.weicome_img1
                        1 -> R.mipmap.weicome_img2
                        else -> R.mipmap.weicome_img3
                    }
                    bean.imgUrl = when(i){
                        0 -> "https://pica.zhimg.com/80/v2-356e983df939e6a7b0d7cb8bbbb1a8cc_720w.jpg"
                        1 -> "https://pic2.zhimg.com/80/v2-0a6815d8628d955b02ad9459d6f2f6c0_720w.jpg"
                        else -> "https://pic.rmb.bdstatic.com/f3fe1eb9f1430476bc3e3dcc3f9efba7.jpeg"
                    }
                    result.add(bean)
                }
                result
            }.runCatching {
                this
            }.onSuccess {
                imgList.value = it
            }.onFailure {
                LogUtils.e("error: $it")
            }
        }
    }

}